package com.qsmx.store.app.main.mem;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatTextView;
import android.view.View;

import com.qsmx.store.app.R;
import com.qsmx.store.app.R2;
import com.qsmx.store.core.delegates.AtmosDelegate;

import butterknife.BindView;
import butterknife.OnClick;

public class MemCardCurrentDelegate extends AtmosDelegate {

    @BindView(R2.id.tv_current_card_sale)
    AppCompatTextView tvCurrentCardSale;
    @BindView(R2.id.tv_current_card_back)
    AppCompatTextView tvCurrentCardBack;
    @BindView(R2.id.tv_current_card_data)
    AppCompatTextView tvCurrentCardData;

    @OnClick(R2.id.tv_current_card_sale)
    void onSaleClick() {
        onSetTitleCheckBg(tvCurrentCardSale);
        getSupportDelegate().replaceChildFragment(new MemCardCurrentInfoDelegate(), false);
    }

    @OnClick(R2.id.tv_current_card_back)
    void onBackClick() {
        onSetTitleCheckBg(tvCurrentCardBack);
        getSupportDelegate().replaceChildFragment(new MemCardCurrentBackDelegate(), false);
    }

    @OnClick(R2.id.tv_current_card_data)
    void onDataClick() {
        onSetTitleCheckBg(tvCurrentCardData);
        getSupportDelegate().replaceChildFragment(new MemCardCurrentRecordDelegate(), false);
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_mem_current_card;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {

        getSupportDelegate().loadRootFragment(R.id.delegate_container, new MemCardCurrentInfoDelegate());

    }

    public void onSetTitleCheckBg(AppCompatTextView tv) {
        tvCurrentCardSale.setBackgroundDrawable(getResources().getDrawable(R.drawable.round_corner_gary_title));
        tvCurrentCardBack.setBackgroundDrawable(getResources().getDrawable(R.drawable.round_corner_gary_title));
        tvCurrentCardData.setBackgroundDrawable(getResources().getDrawable(R.drawable.round_corner_gary_title));

        tvCurrentCardSale.setTextColor(getResources().getColor(R.color.theme_black));
        tvCurrentCardBack.setTextColor(getResources().getColor(R.color.theme_black));
        tvCurrentCardData.setTextColor(getResources().getColor(R.color.theme_black));

        tv.setBackgroundDrawable(getResources().getDrawable(R.drawable.round_corner_title_green_bg));
        tv.setTextColor(getResources().getColor(R.color.theme_white));
    }
}
